package com.chengzhi.netty.handler;

import com.chengzhi.nettycommoms.disruptor.MessageProducer;
import com.chengzhi.nettycommoms.disruptor.RingBufferFactory;
import com.chengzhi.nettycommoms.dto.NettyMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ClientHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        /*try {
            NettyMessage response = (NettyMessage) msg;
            log.info("response paramter ----------" + response.toString());
        } finally {
            ReferenceCountUtil.release(msg);
        }*/
        NettyMessage nettyMessage  = (NettyMessage) msg;
        MessageProducer messageProducer = RingBufferFactory.instance().getMessageProducer("client-producerId");
        messageProducer.send(nettyMessage, ctx);
    }
}
